package com.yzh.TestInetAddress_InetAddress;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;

/**
 * @author : Bruce
 * @date: 2024/7/23 - 07 - 23 - 21:39
 * @Description: com.yzh.TestInetAddress_InetAddress
 * @version: 1.0
 */
public class Test1 {
    public static void main(String[] args) throws UnknownHostException {
        //封装IP：
//        //InetAddress ia = new InetAddress();不能直接创建对象，因为InetAddress()被default修饰了。(只能在当前包下使用)
//        InetAddress ia = InetAddress.getByName("192.168.199.217");
//        System.out.println(ia);
//        InetAddress ia2 = InetAddress.getByName("localhost");//localhost指代的是本机的ip地址
//        System.out.println(ia2);
//        InetAddress ia3 = InetAddress.getByName("127.0.0.1");//127.0.0.1指代的是本机的ip地址
//        System.out.println(ia3);
//        InetAddress ia4 = InetAddress.getByName("LAPTOP-CRIVSRRU");//封装计算机名
//        System.out.println(ia4);
//        InetAddress ia5 = InetAddress.getByName("www.mashibing.com");//封装域名
//        System.out.println(ia5);
//        System.out.println(ia5.getHostName());//获取域名
//        System.out.println(ia5.getHostAddress());//获取ip地址

//        InetAddress ia = InetAddress.getByName("localhost");
//        System.out.println(ia);
//        InetAddress ia2 = InetAddress.getByName("TinkPad-YZH");
//        System.out.println(ia2);
//        InetAddress ia3 = InetAddress.getByName("www.baidu.com");
//        System.out.println(ia3);
//        System.out.println(ia3.getHostAddress());//获取ip地址
//        System.out.println(ia3.getHostName());//获取域名



//        InetSocketAddress isa = new InetSocketAddress("192.168.199.217",8080);
//        System.out.println(isa);
//        System.out.println(isa.getHostName());
//        System.out.println(isa.getPort());
//        InetAddress ia = isa.getAddress();
//        System.out.println(ia.getHostName());
//        System.out.println(ia.getHostAddress());

        InetSocketAddress isa = new InetSocketAddress("192.168.199.217",8080);
        System.out.println(isa);
        System.out.println(isa.getHostName());
        System.out.println(isa.getPort());
    }
}
